<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03-H5获取元素</title>
</head>
<body>
    <div class="box">盒子1</div>
    <div class="box">盒子2</div>
    <div id = "nav"></div>
    <ul>
        <li>好久不见</li>
        <li>富士山下</li>
        <li>浮夸</li>
        <li>因为爱情</li>
    </ul>
    <script>
        // 1. getElementsByClassName  根据类名获得某些元素的集合
        let boxs = document.getElementsByClassName('box');
        console.log(boxs);

        // 2. 返回符合条件的第一个元素
        console.log(document.querySelector('#nav'));  // id   <div id = "nav"></div>
        console.log(document.querySelector('.box'));  // 类名  <div class="box">盒子1</div>
        console.log(document.querySelector('li'));  // 标签  <li>好久不见</li>

        // 3. 返回数组
        console.log(document.querySelectorAll('li'));  // 返回4个li
    </script>
</body>
</html>